package com.qf.personal.service.impl;

import com.qf.common.base.exception.ServiceException;
import com.qf.common.base.result.RespResult;
import com.qf.common.base.result.ResultCode;
import com.qf.personal.entiy.Things;
import com.qf.personal.entiy.Vo.EmpVo;
import com.qf.personal.mapper.IndexMapper;
import com.qf.personal.service.IndexService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils;

import javax.annotation.Resource;
import java.util.List;

@Service
public class IndexServiceImpl implements IndexService {
    @Resource
    private IndexMapper indexMapper;

    @Override
    public RespResult<EmpVo> selectById(int id) {
        EmpVo empVo = indexMapper.selectById(id);
        if (empVo != null) {
            return RespResult.success(empVo);
        } else {
            throw new ServiceException(ResultCode.SYS_ERROR);
        }
    }

    @Override
    @Transactional
    public RespResult<List<Things>> selectAll(Things things) {
        Things things1 = new Things();
        List<Things> list = indexMapper.selectAll(things);
        return RespResult.success(list);
    }

    @Override
    public RespResult<List<Things>> selectThings(Things things) {
        List<Things> list = indexMapper.selectThings(things);
        if (!ObjectUtils.isEmpty(list)) {
            return RespResult.success(list);
        } else {
            throw new ServiceException(ResultCode.SYS_ERROR);
        }
    }
}
